package hotel;

import java.util.Calendar;

import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.List;

public class addReserve {
	private Text tDataIn;
	private Text tDataOut;
	int ndayIn = 0;
	int nMouthIn = 0;
	int nYearIn = 0;
	/**
	 * Open the window.
	 * @wbp.parser.entryPoint
	 */
	public void open() {
		Display display = Display.getDefault();
		Shell shell = new Shell();
		shell.setSize(498, 383);
		shell.setText("\u0420\u0435\u0437\u0435\u0440\u0432\u0430\u0446\u0438\u044F");
		shell.setLayout(new GridLayout(3, false));
		
		Label label = new Label(shell, SWT.NONE);
		label.setFont(SWTResourceManager.getFont("Arial", 9, SWT.BOLD));
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label.setText("\u0414\u0430\u0442\u0430 \u043D\u0430 \u043F\u0440\u0438\u0441\u0442\u0438\u0433\u0430\u043D\u0435: ");
		
		tDataIn = new Text(shell, SWT.BORDER | SWT.READ_ONLY);
		tDataIn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		
		Button btnNewButton = new Button(shell, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent arg0) {
				
				Display shell = null;
				final Shell dialog = new Shell (shell, SWT.DIALOG_TRIM);
				dialog.setLayout (new GridLayout (3, false));

				final DateTime calendar = new DateTime (dialog, SWT.CALENDAR | SWT.BORDER);
				new Label (dialog, SWT.NONE);
				new Label (dialog, SWT.NONE);
				Button ok = new Button (dialog, SWT.PUSH);
				ok.setText ("OK");
				ok.setLayoutData(new GridData (SWT.FILL, SWT.CENTER, false, false));
				ok.addSelectionListener (new SelectionAdapter () {
					public void widgetSelected (SelectionEvent e) {
						ndayIn = calendar.getDay();
						nMouthIn = calendar.getMonth();
						nYearIn = calendar.getYear();
						
						String sDayIn = Integer.toString(ndayIn);
						String sMouthIn = Integer.toString(nMouthIn);
						String sYearIn = Integer.toString(nYearIn);
						
						String sAllDataIn = sDayIn + "/" + sMouthIn + "/" + sYearIn;
						System.out.println (sAllDataIn);
						tDataIn.setText(sAllDataIn);
						
						Calendar calendar = Calendar.getInstance();
						calendar.set(nYearIn, nMouthIn, 1);

						int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
						System.out.println("Max Day: " + maxDay);

		
						  
						  
						dialog.close ();
					}
				});
				dialog.setDefaultButton (ok);
				dialog.pack ();
				dialog.open ();
				
			}
		});
		btnNewButton.setText("\u0438\u0437\u0431\u0435\u0440\u0438");
		
		Label label_1 = new Label(shell, SWT.NONE | SWT.READ_ONLY);
		label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_1.setFont(SWTResourceManager.getFont("Arial", 9, SWT.BOLD));
		label_1.setText("\u0414\u0430\u0442\u0430 \u043D\u0430 \u0437\u0430\u043C\u0438\u043D\u0430\u0432\u0430\u043D\u0435: ");
		
		tDataOut = new Text(shell, SWT.BORDER);
		tDataOut.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Button btnNewButton_1 = new Button(shell, SWT.NONE);
		btnNewButton_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent arg0) {
				
				Display shell = null;
				final Shell dialog = new Shell (shell, SWT.DIALOG_TRIM);
				dialog.setLayout (new GridLayout (3, false));

				final DateTime calendar = new DateTime (dialog, SWT.CALENDAR | SWT.BORDER);
				new Label (dialog, SWT.NONE);
				new Label (dialog, SWT.NONE);
				Button ok = new Button (dialog, SWT.PUSH);
				ok.setText ("OK");
				ok.setLayoutData(new GridData (SWT.FILL, SWT.CENTER, false, false));
				ok.addSelectionListener (new SelectionAdapter () {
					public void widgetSelected (SelectionEvent e) {
						int ndayOut = calendar.getDay();
						int nMouthOut = calendar.getMonth();
						int nYearOut = calendar.getYear();
						
						String sDayOut = Integer.toString(ndayOut);
						String sMouthOut = Integer.toString(nMouthOut);
						String sYearOut = Integer.toString(nYearOut);
						
						String sAllDataOut = sDayOut + "/" + sMouthOut + "/" + sYearOut;
						System.out.println (sAllDataOut);
						tDataOut.setText(sAllDataOut);
						
						dialog.close ();
					}
				});
				dialog.setDefaultButton (ok);
				dialog.pack ();
				dialog.open ();
			
			}
		});
		btnNewButton_1.setText("\u0438\u0437\u0431\u0435\u0440\u0438");
		
		Label label_4 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
		GridData gd_label_4 = new GridData(SWT.CENTER, SWT.CENTER, false, false, 3, 1);
		gd_label_4.heightHint = 15;
		gd_label_4.widthHint = 443;
		label_4.setLayoutData(gd_label_4);
		
		Label label_2 = new Label(shell, SWT.NONE);
		label_2.setFont(SWTResourceManager.getFont("Arial", 12, SWT.BOLD));
		label_2.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
		label_2.setText("\u0421\u0442\u0430\u0438");
		new Label(shell, SWT.NONE);
		
		Label label_3 = new Label(shell, SWT.NONE);
		label_3.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
		label_3.setFont(SWTResourceManager.getFont("Arial", 12, SWT.BOLD));
		label_3.setText("\u0418\u0437\u0431\u0440\u0430\u043D\u0438 \u0441\u0442\u0430\u0438");
		
		List list = new List(shell, SWT.BORDER);
		GridData gd_list = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_list.heightHint = 100;
		gd_list.widthHint = 185;
		list.setLayoutData(gd_list);
		new Label(shell, SWT.NONE);
		
		List list_1 = new List(shell, SWT.BORDER);
		GridData gd_list_1 = new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1);
		gd_list_1.heightHint = 100;
		gd_list_1.widthHint = 185;
		list_1.setLayoutData(gd_list_1);

		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

}
